package com.xhh.nphm.gaoxin.controller;

import com.xhh.nphm.common.core.controller.BaseController;
import com.xhh.nphm.common.core.domain.AjaxResult;
import com.xhh.nphm.common.core.domain.entity.Dept;
import com.xhh.nphm.common.core.page.TableDataInfo;
import com.xhh.nphm.gaoxin.entity.GxqTtelGetDealEty;
import com.xhh.nphm.gaoxin.entity.GxqTworkFormBaseEty;
import com.xhh.nphm.gaoxin.entity.GxqTworkFormLogEty;
import com.xhh.nphm.gaoxin.service.GxqITelGetDealService;
import com.xhh.nphm.gaoxin.service.GxqITworkFormLogService;
import com.xhh.nphm.gaoxin.service.GxqIWorkFormBaseService;
import com.xhh.nphm.gaoxin.mapper.GxqTestMapper;
import com.xhh.nphm.gaoxin.service.impl.GxqTestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/gaoxin/system/test")
public class GxqSysTestController extends BaseController {
    private String prefix = "system/gaoxin/test";

    @Autowired
    private GxqTestService gxqTestService;

    @Autowired
    private GxqIWorkFormBaseService gxqWorkFormBaseService;

    @Autowired
    private GxqITworkFormLogService gxqTworkFormLogService;

    @Autowired
    private GxqITelGetDealService gxqTelGetDealService;

    @Autowired
    private GxqTestMapper gxqTestMapper;

    @GetMapping("caseDetail/{pkId}")
    public ModelAndView caseDetail(@PathVariable("pkId") Integer pkId, ModelMap map) {
        GxqTworkFormBaseEty GxqTworkFormBaseEty = gxqWorkFormBaseService.getById(pkId);
        GxqTtelGetDealEty GxqTtelGetDealEty = gxqTelGetDealService.getById(GxqTworkFormBaseEty.getGetDealPk());
        if (GxqTworkFormBaseEty != null) {
            map.put("workFormBase", GxqTworkFormBaseEty);
            map.put("telGetDeal", GxqTtelGetDealEty);
        }
        return new ModelAndView(prefix + "/caseDetail");
    }

    /**
     *根据工单号查询工单pkId
     * @param workNo
     * @return
     */
    @PostMapping("caseDetailTel/{workNo}")
    public AjaxResult caseDetailTel(@PathVariable("workNo") String workNo) {
        AjaxResult ajaxResult = new AjaxResult();
        GxqTworkFormBaseEty GxqTworkFormBaseEty = gxqWorkFormBaseService.getByWorkNo(workNo);
        if (GxqTworkFormBaseEty==null){
            return null;
        }
        int pkId = GxqTworkFormBaseEty.getPkId();
        ajaxResult.put("pkId",pkId);
        return ajaxResult;
    }

    @GetMapping("sendBackRecord")
    public ModelAndView sendBackRecord() {
        return new ModelAndView(prefix + "/sendBackRecord");
    }

    @GetMapping("workFormLog")
    public ModelAndView workFormLog(int pkId, HttpServletRequest request) {
        request.setAttribute("pkId",pkId);
        return new ModelAndView(prefix + "/workFormLog");
    }

    /**
     * 操作记录列表
     *
     * @param pkId
     * @return
     */
    @RequestMapping("/workFormLogList")
    public TableDataInfo workFormLogList(int pkId) {
        startPage();
        List<GxqTworkFormLogEty> list = gxqTworkFormLogService.logListJson(pkId);
        return getDataTable(list);
    }

    @GetMapping("lablePage")
    public ModelAndView lablePage() {
        return new ModelAndView(prefix + "/lablePage");
    }

    @GetMapping("test")
    public ModelAndView test() {
        return new ModelAndView(prefix + "/test");
    }


    @GetMapping("deptTransfer")
    public ModelAndView deptTransfer() {
        return new ModelAndView(prefix + "/deptTransfer");
    }

    @GetMapping("alreadyBakTwfb")
    public ModelAndView alreadyBakTwfb() {
        return new ModelAndView(prefix + "/alreadyBakTwfb");
    }

    @GetMapping("/extension")
    public ModelAndView extension() {
        return new ModelAndView(prefix + "/extension");
    }

    @GetMapping("telbackaudit")
    public ModelAndView telBackAudit() {
        return new ModelAndView(prefix + "/telbackaudit");
    }

    @GetMapping("/telbackaudit2")
    public ModelAndView telBackAudit2() {
        return new ModelAndView(prefix + "/telbackaudit2");
    }

    @GetMapping("/tworkformadd")
    public ModelAndView tworkformadd() {
        return new ModelAndView(prefix + "/tworkformadd");
    }

    @GetMapping("/deptdiag")
    public ModelAndView deptdiag() {
        return new ModelAndView(prefix + "/deptdiag");
    }

    @GetMapping("/teladd")
    public ModelAndView telBlack() {
        return new ModelAndView(prefix + "/teladd");
    }

    @GetMapping("/telhandle")
    public ModelAndView telhandle() {
        return new ModelAndView(prefix + "/telhandle");
    }

    @GetMapping("/teldetail")
    public ModelAndView teldetail() {
        return new ModelAndView(prefix + "/teldetail");
    }

    @GetMapping("/teladd2")
    public ModelAndView telBlack2() {
        return new ModelAndView(prefix + "/teladd2");
    }

    @GetMapping("/teladd3")
    public ModelAndView telBlack3() {
        return new ModelAndView(prefix + "/teladd3");
    }

    @GetMapping("/teladd4")
    public ModelAndView telBlack4() {
        return new ModelAndView(prefix + "/teladd4");
    }

    @GetMapping("/similarList")
    public ModelAndView similarList() {
        return new ModelAndView(prefix + "/similarList");
    }

    @GetMapping("/particulars")
    public ModelAndView particulars() {
        return new ModelAndView(prefix + "/particulars");
    }

    @GetMapping("/tel")
    public ModelAndView tel() {
        return new ModelAndView(prefix + "/tel");
    }

    @RequestMapping("telList1")
    public Object telList1(GxqTtelGetDealEty GxqTtelGetDealEty) {
//        if(StringUtils.isNotEmpty(GxqTtelGetDealEty.getFmContent())) {
            startPage();
            List<Map<String, Object>> list = gxqTestService.selectList(GxqTtelGetDealEty);
            return getDataTable(list);
//        }
//        return null;
    }

    /**
     * 查看已删除工单详情
     * @param pkId
     * @return
     */
    @GetMapping("caseDeleteDetail/{pkId}")
    public ModelAndView caseDeleteDetail(@PathVariable("pkId") Integer pkId, ModelMap map) {
        GxqTworkFormBaseEty GxqTworkFormBaseEty = gxqWorkFormBaseService.getByPkId(pkId);
        GxqTtelGetDealEty GxqTtelGetDealEty = gxqTelGetDealService.selectByTelPkId(GxqTworkFormBaseEty.getGetDealPk());
        if (GxqTworkFormBaseEty != null) {
            map.put("workFormBase", GxqTworkFormBaseEty);
            map.put("telGetDeal", GxqTtelGetDealEty);
        }
        return new ModelAndView(prefix + "/caseDetail");
    }

    @RequestMapping("telList")
    public Object telList(GxqTtelGetDealEty GxqTtelGetDealEty) {
        Dept dept = new Dept();
        dept.setNoParent("301040");
        List<Dept> deptList = gxqTestMapper.selectByCondition(dept);
        return deptList;
    }
}
